/*
 * TODO language 
 * Copyright (c) 2010 TODO Team
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

#include "API.h"
#include "types.h"
#include "object.h"

namespace todo { namespace type {

Object::Object() : Type("object") 
{
}

void Object::load(void)
{
	// Methods
	register_method(TODO_PUBLIC, "toString"   , "string", (MethodPtr)&Object::toString);
	register_method(TODO_PUBLIC, "getClass"   , "string", (MethodPtr)&Object::getClass);
	register_method(TODO_PUBLIC, "hasProperty", "bool"  , (MethodPtr)&Object::hasProperty, 1, type_list(1, "string"));
	register_method(TODO_PUBLIC, "hasMethod"  , "bool"  , (MethodPtr)&Object::hasMethod  , 1, type_list(1, "string"));
}
	
/**
 * string object::toString( void )
 */
TODO_METHOD(Object, toString)
{
	Value *v = NEW("string");
	
	STR_P(v)->assign(value->type->get_name());
	
	return v;
}

/**
 * string object::getClass( void )
 */
TODO_METHOD(Object, getClass)
{
	Value *v = NEW("string");
	
	STR_P(v)->assign(value->type->get_name());
	
	return v;
}

/**
 * string object::hasProperty( string )
 */
TODO_METHOD(Object, hasProperty)
{
	Value *v = NEW("bool");

	BOOL_V(v) = value->type->has_property(STR_V(ARG(0)));
	
	return v;
}

/**
 * string object::hasMethod( string )
 */
TODO_METHOD(Object, hasMethod)
{
	Value *v = NEW("bool");

	BOOL_V(v) = value->type->has_method(STR_V(ARG(0)));
	
	return v;
}

/**
 * Allocs an object value
 */
Value* Object::alloc()
{
	return new Value(this, NULL);
}

/**
 * Copies an object value
 */
Value* Object::copy(const Value* value)
{
	return new Value(this, NULL);
}

/**
 * Deallocs an object value
 */
void Object::dealloc(Value* value)
{
	value->properties.clear();
	/* No data to delete */
	delete value;
}

VarArg::VarArg() : Type("vararg", TYPE_P("object")) 
{
}

void VarArg::load(void)
{
	// Methods
	register_method(TODO_PUBLIC, "toString", "string", (MethodPtr)&VarArg::toString);
}
	
/**
 * string object::toString( void )
 */
TODO_METHOD(VarArg, toString)
{
	Value *v = NEW("string");
	
	STR_P(v)->assign(value->type->get_name());
	
	return v;
}

/**
 * Allocs an VarArg value
 */
Value* VarArg::alloc()
{
	return new Value(this, NULL);
}

/**
 * Copies an VarArg value
 */
Value* VarArg::copy(const Value* value)
{
	return new Value(this, NULL);
}

/**
 * Deallocs an VarArg value
 */
void VarArg::dealloc(Value* value)
{
	value->properties.clear();
	/* No data to delete */
	delete value;
}

}} // todo::type
